// Copyright (c) 2009 Alistair Jones
// This program is made available under the terms of the MIT License.
package org.hypirinha.html.codegen;

import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.hypirinha.html.codegen.MemberExpectations.*;
import static org.hypirinha.html.codegen.MemberExpectations.member;

import java.util.HashSet;
import java.util.ArrayList;
import java.util.List;

public class ElementFactoryTest {

    @Test
    public void shouldGenerateMethodsThatInstantiateElements() {
        List<String> elements = new ArrayList<String>();
        elements.add("earth");
        elements.add("air");
        elements.add("fire");
        elements.add("water");
        ElementFactory element = new ElementFactory(elements);
        GeneratedClass generatedClass = element.createImplementation();

        List<Member> members = generatedClass.getMembers();
        assertEquals(5, members.size());

        ConcreteMethod method = (ConcreteMethod) members.get(0);
        assertEquals("air", method.getMethodName());
        assertEquals("Air", method.getReturnType());
        assertEquals("return new AirElement(attributes);", method.getMethodBody());
        assertTrue(method.getModifiers().contains("static"));
    }

    @Test
    public void shouldGenerateMethodForCreatingTextNodes() {
        ElementFactory element = new ElementFactory(new ArrayList<String>());
        GeneratedClass generatedClass = element.createImplementation();

        List<Member> members = generatedClass.getMembers();
        assertEquals(1, members.size());

        ConcreteMethod method = (ConcreteMethod) members.get(0);
        assertEquals("text", method.getMethodName());
        assertEquals("Text", method.getReturnType());
        assertEquals("return new Text(content);", method.getMethodBody());
        assertTrue(method.getModifiers().contains("static"));
    }

}